package com.project.common.controller;

import com.project.common.entity.PageVo;
import com.project.common.entity.SysRoles;
import com.project.common.entity.SysUserRole;
import com.project.common.mapper.SysUserRoleMapper;
import com.project.common.service.SysRoleUserService;
import com.project.common.service.SysRolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sysRoles")
public class SysRolesController {
    @Autowired
    private SysRolesService sysRolesService;

    @Autowired
    private SysRoleUserService sysRoleUserService;
    @PostMapping("/queryAllRoles.action")
    public PageVo<SysRoles> queryAllRolesAction(@RequestBody Map<String,String> map){
        PageVo<SysRoles> sysRolesPageVo = sysRolesService.queryAllRoles(map);
        return sysRolesPageVo;
    }
    @PostMapping("/queryAllRoles")
    public PageVo<SysRoles> queryAllRoles(@RequestBody Map<String,String> map){
        PageVo<SysRoles> sysRolesPageVo = sysRolesService.queryAllRoles(map);
        return sysRolesPageVo;
    }
    @PostMapping("/queryAllRole1.action")
    @ResponseBody
    public List<SysRoles> queryAllRole1(){
        List<SysRoles> sysRoles = sysRolesService.queryAllRoles();
        return sysRoles;
    }

    @PostMapping("queryRoleByUserId.action")
    @ResponseBody
    public List<SysRoles> queryRoleByUserId(Integer userId){
        List<SysUserRole> sysUserRoles = sysRoleUserService.queryByUserId(userId);
        List<SysRoles> roles = new ArrayList<SysRoles>();
        for (int i=0;i<sysUserRoles.size();i++){
            SysRoles sysRoles = sysRolesService.selectByPrimaryKey(sysUserRoles.get(i).getRoleId());
            roles.add(sysRoles);
        }
        return roles;
    }
}
